﻿#include "OperCSVIntermediateAmount.h"
#include "PickDataProvider/PickedDataProvider.h"
#include "PickDataProvider/GUIPickInfo.h"
#include "PickDataProvider/PickedData.h"
#include "OperatorsInterface/GraphEventOperator.h"
#include "GUIFrame/MainWindow.h"
#include "GUIDialog/GUIPostDialog/GUICSVParameterDialog.h"
#include "FITK_Component/FITKAcousticsPostData/FITKAcousticsCSVParameter.h"

#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Kernel/FITKAppFramework/FITKMessage.h"

#include <QAction>

namespace ModelOper
{

    bool OperCSVIntermediateAmount::execGUI()
    {
        //拾取模式
        GraphData::PickedDataProvider* provider = GraphData::PickedDataProvider::getInstance();
        if (provider == nullptr)return false;
        //清除拾取对象所有的连接
        QObject::disconnect(provider, SIGNAL(sig_pickedOver()), nullptr, nullptr);
        //清除拾取模式和高亮
        GUI::GUIPickInfo::ClearPickInfo();
        //获取主窗口和动作对象
        QWidget* mainWindow = FITKAPP->getGlobalData()->getMainWindow();
        QAction* action = dynamic_cast<QAction*>(_emitter);
        if (!mainWindow || !action) return false;
        //获取选择
        bool isChecked = action->isChecked();
        if (!isChecked) return false;
        //绑定拾取信号
        connect(provider, SIGNAL(sig_pickedOver()), this, SLOT(slotPickOverEvent()));
        //拾取模式选择
        GUI::GUIPickInfoStru pickStr;
        pickStr._pickObjType = GUI::GUIPickInfo::PickObjType::POBJNone;
        int actionType = action->data().toInt();
        if (actionType == 0 || actionType == 1)
            pickStr._pickObjType = GUI::GUIPickInfo::PickObjType::POBJSEASubSystem;
        else if (actionType == 2 || actionType == 3)
            pickStr._pickObjType = GUI::GUIPickInfo::PickObjType::POBJSEAJunctions;
        //开启拾取模式
        pickStr._pickMethod = GUI::GUIPickInfo::PickMethod::PMSingle;
        GUI::GUIPickInfo::SetPickInfo(pickStr);
       
        return false;
    }

    bool OperCSVIntermediateAmount::execProfession()
    {
        return true;
    }

    void OperCSVIntermediateAmount::slotPickOverEvent()
    {
        //获取主窗口和动作对象
        QWidget* mainWindow = FITKAPP->getGlobalData()->getMainWindow();
        QAction* action = dynamic_cast<QAction*>(_emitter);
        if (!mainWindow || !action) return;
        action->setChecked(false);
        //获取三维可视化对象管理
        GraphData::PickedDataProvider* provider = GraphData::PickedDataProvider::getInstance();
        if (!provider)return;
        //清除拾取对象所有的连接
        QObject::disconnect(provider, SIGNAL(sig_pickedOver()), nullptr, nullptr);
        //获取拾取数据对象
        QList<GraphData::PickedData*> pickList = provider->getPickedList();
        if (pickList.isEmpty() || !pickList.at(0))return;
        int objID = pickList.at(0)->getPickedDataObjId();
        //获取类型
        int actionType = action->data().toInt();
        Acoustics::FITKAcousticsCSVParameter::CSVParameterType paraType = Acoustics::FITKAcousticsCSVParameter::CSVParameterType::ParaNone;
        if (actionType == 0)
            //模态密度
            paraType = Acoustics::FITKAcousticsCSVParameter::CSVParameterType::ModalDensity;
        else if (actionType == 1)
            //损耗因子
            paraType = Acoustics::FITKAcousticsCSVParameter::CSVParameterType::LossFactor;
        else if (actionType == 2)
            //耦合损耗因子
            paraType = Acoustics::FITKAcousticsCSVParameter::CSVParameterType::CLF;
        else if (actionType == 3)
            //辐射效率
            paraType = Acoustics::FITKAcousticsCSVParameter::CSVParameterType::RadiationEfficiency;
        //清除拾取模式和高亮
        GUI::GUIPickInfo::ClearPickInfo();
        //创建窗口
        GUI::GUICSVParameterDialog* dialog = new GUI::GUICSVParameterDialog(this, mainWindow);
        dialog->setCSVPara(objID, paraType);
        dialog->init();
        dialog->show();
    }
}

